package pe.gob.mpfn.controller;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.faces.application.Application;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.html.HtmlOutputText;
import javax.faces.component.html.HtmlPanelGrid;
import javax.faces.context.FacesContext;
import javax.faces.convert.DateTimeConverter;
import javax.faces.validator.LengthValidator;
import org.primefaces.component.autocomplete.AutoComplete;
import org.primefaces.component.calendar.Calendar;
import org.primefaces.component.inputtext.InputText;
import org.primefaces.component.inputtextarea.InputTextarea;
import org.primefaces.component.message.Message;
import org.primefaces.context.RequestContext;
import org.primefaces.event.CloseEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.roo.addon.jsf.managedbean.RooJsfManagedBean;
import org.springframework.roo.addon.serializable.RooSerializable;
import pe.gob.mpfn.controller.converter.DiligenciaConverter;
import pe.gob.mpfn.model.DetalleDiligencia;
import pe.gob.mpfn.model.Diligencia;
import pe.gob.mpfn.service.DetalleDiligenciaService;
import pe.gob.mpfn.service.DiligenciaService;

@ManagedBean(name = "detalleDiligenciaBean")
@SessionScoped
@Configurable
@RooSerializable
@RooJsfManagedBean(entity = DetalleDiligencia.class, beanName = "detalleDiligenciaBean")
public class DetalleDiligenciaBean implements Serializable  {

	@Autowired
    DetalleDiligenciaService detalleDiligenciaService;

	@Autowired
    DiligenciaService diligenciaService;

	private String name = "DetalleDiligencias";

	private DetalleDiligencia detalleDiligencia;

	private List<DetalleDiligencia> allDetalleDiligencias;

	private boolean dataVisible = false;

	private List<String> columns;

	private HtmlPanelGrid createPanelGrid;

	private HtmlPanelGrid editPanelGrid;

	private HtmlPanelGrid viewPanelGrid;

	private boolean createDialogVisible = false;

	@PostConstruct
    public void init() {
        columns = new ArrayList<String>();
        columns.add("strDescripcion");
        columns.add("strResponsable");
        columns.add("datFechaRegistro");
        columns.add("txtImagen");
        columns.add("chrEstado");
    }

	public String getName() {
        return name;
    }

	public List<String> getColumns() {
        return columns;
    }

	public List<DetalleDiligencia> getAllDetalleDiligencias() {
        return allDetalleDiligencias;
    }

	public void setAllDetalleDiligencias(List<DetalleDiligencia> allDetalleDiligencias) {
        this.allDetalleDiligencias = allDetalleDiligencias;
    }

	public String findAllDetalleDiligencias() {
        allDetalleDiligencias = detalleDiligenciaService.findAllDetalleDiligencias();
        dataVisible = !allDetalleDiligencias.isEmpty();
        return null;
    }

	public boolean isDataVisible() {
        return dataVisible;
    }

	public void setDataVisible(boolean dataVisible) {
        this.dataVisible = dataVisible;
    }

	public HtmlPanelGrid getCreatePanelGrid() {
        if (createPanelGrid == null) {
            createPanelGrid = populateCreatePanel();
        }
        return createPanelGrid;
    }

	public void setCreatePanelGrid(HtmlPanelGrid createPanelGrid) {
        this.createPanelGrid = createPanelGrid;
    }

	public HtmlPanelGrid getEditPanelGrid() {
        if (editPanelGrid == null) {
            editPanelGrid = populateEditPanel();
        }
        return editPanelGrid;
    }

	public void setEditPanelGrid(HtmlPanelGrid editPanelGrid) {
        this.editPanelGrid = editPanelGrid;
    }

	public HtmlPanelGrid getViewPanelGrid() {
        if (viewPanelGrid == null) {
            viewPanelGrid = populateViewPanel();
        }
        return viewPanelGrid;
    }

	public void setViewPanelGrid(HtmlPanelGrid viewPanelGrid) {
        this.viewPanelGrid = viewPanelGrid;
    }

	public HtmlPanelGrid populateCreatePanel() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application application = facesContext.getApplication();
        ExpressionFactory expressionFactory = application.getExpressionFactory();
        ELContext elContext = facesContext.getELContext();
        
        HtmlPanelGrid htmlPanelGrid = (HtmlPanelGrid) application.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
        
        HtmlOutputText intDiligenciaIdCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        intDiligenciaIdCreateOutput.setId("intDiligenciaIdCreateOutput");
        intDiligenciaIdCreateOutput.setValue("Int Diligencia Id:   ");
        htmlPanelGrid.getChildren().add(intDiligenciaIdCreateOutput);
        
        AutoComplete intDiligenciaIdCreateInput = (AutoComplete) application.createComponent(AutoComplete.COMPONENT_TYPE);
        intDiligenciaIdCreateInput.setId("intDiligenciaIdCreateInput");
        intDiligenciaIdCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.intDiligenciaId}", Diligencia.class));
        intDiligenciaIdCreateInput.setCompleteMethod(expressionFactory.createMethodExpression(elContext, "#{detalleDiligenciaBean.completeIntDiligenciaId}", List.class, new Class[] { String.class }));
        intDiligenciaIdCreateInput.setDropdown(true);
        intDiligenciaIdCreateInput.setValueExpression("var", expressionFactory.createValueExpression(elContext, "intDiligenciaId", String.class));
        intDiligenciaIdCreateInput.setValueExpression("itemLabel", expressionFactory.createValueExpression(elContext, "#{intDiligenciaId.datFechaInicio} #{intDiligenciaId.datFechaFin} #{intDiligenciaId.strObservacion} #{intDiligenciaId.chrEstado}", String.class));
        intDiligenciaIdCreateInput.setValueExpression("itemValue", expressionFactory.createValueExpression(elContext, "#{intDiligenciaId}", Diligencia.class));
        intDiligenciaIdCreateInput.setConverter(new DiligenciaConverter());
        intDiligenciaIdCreateInput.setRequired(false);
        htmlPanelGrid.getChildren().add(intDiligenciaIdCreateInput);
        
        Message intDiligenciaIdCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        intDiligenciaIdCreateInputMessage.setId("intDiligenciaIdCreateInputMessage");
        intDiligenciaIdCreateInputMessage.setFor("intDiligenciaIdCreateInput");
        intDiligenciaIdCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(intDiligenciaIdCreateInputMessage);
        
        HtmlOutputText strDescripcionCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strDescripcionCreateOutput.setId("strDescripcionCreateOutput");
        strDescripcionCreateOutput.setValue("Str Descripcion: * ");
        htmlPanelGrid.getChildren().add(strDescripcionCreateOutput);
        
        InputTextarea strDescripcionCreateInput = (InputTextarea) application.createComponent(InputTextarea.COMPONENT_TYPE);
        strDescripcionCreateInput.setId("strDescripcionCreateInput");
        strDescripcionCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.strDescripcion}", String.class));
        LengthValidator strDescripcionCreateInputValidator = new LengthValidator();
        strDescripcionCreateInputValidator.setMaximum(200);
        strDescripcionCreateInput.addValidator(strDescripcionCreateInputValidator);
        strDescripcionCreateInput.setRequired(true);
        htmlPanelGrid.getChildren().add(strDescripcionCreateInput);
        
        Message strDescripcionCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        strDescripcionCreateInputMessage.setId("strDescripcionCreateInputMessage");
        strDescripcionCreateInputMessage.setFor("strDescripcionCreateInput");
        strDescripcionCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(strDescripcionCreateInputMessage);
        
        HtmlOutputText strResponsableCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strResponsableCreateOutput.setId("strResponsableCreateOutput");
        strResponsableCreateOutput.setValue("Str Responsable: * ");
        htmlPanelGrid.getChildren().add(strResponsableCreateOutput);
        
        InputTextarea strResponsableCreateInput = (InputTextarea) application.createComponent(InputTextarea.COMPONENT_TYPE);
        strResponsableCreateInput.setId("strResponsableCreateInput");
        strResponsableCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.strResponsable}", String.class));
        LengthValidator strResponsableCreateInputValidator = new LengthValidator();
        strResponsableCreateInputValidator.setMaximum(200);
        strResponsableCreateInput.addValidator(strResponsableCreateInputValidator);
        strResponsableCreateInput.setRequired(true);
        htmlPanelGrid.getChildren().add(strResponsableCreateInput);
        
        Message strResponsableCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        strResponsableCreateInputMessage.setId("strResponsableCreateInputMessage");
        strResponsableCreateInputMessage.setFor("strResponsableCreateInput");
        strResponsableCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(strResponsableCreateInputMessage);
        
        HtmlOutputText datFechaRegistroCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        datFechaRegistroCreateOutput.setId("datFechaRegistroCreateOutput");
        datFechaRegistroCreateOutput.setValue("Dat Fecha Registro: * ");
        htmlPanelGrid.getChildren().add(datFechaRegistroCreateOutput);
        
        Calendar datFechaRegistroCreateInput = (Calendar) application.createComponent(Calendar.COMPONENT_TYPE);
        datFechaRegistroCreateInput.setId("datFechaRegistroCreateInput");
        datFechaRegistroCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.datFechaRegistro}", Date.class));
        datFechaRegistroCreateInput.setNavigator(true);
        datFechaRegistroCreateInput.setEffect("slideDown");
        datFechaRegistroCreateInput.setPattern("dd/MM/yyyy");
        datFechaRegistroCreateInput.setRequired(true);
        htmlPanelGrid.getChildren().add(datFechaRegistroCreateInput);
        
        Message datFechaRegistroCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        datFechaRegistroCreateInputMessage.setId("datFechaRegistroCreateInputMessage");
        datFechaRegistroCreateInputMessage.setFor("datFechaRegistroCreateInput");
        datFechaRegistroCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(datFechaRegistroCreateInputMessage);
        
        HtmlOutputText txtImagenCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        txtImagenCreateOutput.setId("txtImagenCreateOutput");
        txtImagenCreateOutput.setValue("Txt Imagen: * ");
        htmlPanelGrid.getChildren().add(txtImagenCreateOutput);
        
        InputText txtImagenCreateInput = (InputText) application.createComponent(InputText.COMPONENT_TYPE);
        txtImagenCreateInput.setId("txtImagenCreateInput");
        txtImagenCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.txtImagen}", String.class));
        htmlPanelGrid.getChildren().add(txtImagenCreateInput);
        
        Message txtImagenCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        txtImagenCreateInputMessage.setId("txtImagenCreateInputMessage");
        txtImagenCreateInputMessage.setFor("txtImagenCreateInput");
        txtImagenCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(txtImagenCreateInputMessage);
        
        HtmlOutputText chrEstadoCreateOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        chrEstadoCreateOutput.setId("chrEstadoCreateOutput");
        chrEstadoCreateOutput.setValue("Chr Estado: * ");
        htmlPanelGrid.getChildren().add(chrEstadoCreateOutput);
        
        InputText chrEstadoCreateInput = (InputText) application.createComponent(InputText.COMPONENT_TYPE);
        chrEstadoCreateInput.setId("chrEstadoCreateInput");
        chrEstadoCreateInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.chrEstado}", Character.class));
        chrEstadoCreateInput.setRequired(true);
        htmlPanelGrid.getChildren().add(chrEstadoCreateInput);
        
        Message chrEstadoCreateInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        chrEstadoCreateInputMessage.setId("chrEstadoCreateInputMessage");
        chrEstadoCreateInputMessage.setFor("chrEstadoCreateInput");
        chrEstadoCreateInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(chrEstadoCreateInputMessage);
        
        return htmlPanelGrid;
    }

	public HtmlPanelGrid populateEditPanel() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application application = facesContext.getApplication();
        ExpressionFactory expressionFactory = application.getExpressionFactory();
        ELContext elContext = facesContext.getELContext();
        
        HtmlPanelGrid htmlPanelGrid = (HtmlPanelGrid) application.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
        
        HtmlOutputText intDiligenciaIdEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        intDiligenciaIdEditOutput.setId("intDiligenciaIdEditOutput");
        intDiligenciaIdEditOutput.setValue("Int Diligencia Id:   ");
        htmlPanelGrid.getChildren().add(intDiligenciaIdEditOutput);
        
        AutoComplete intDiligenciaIdEditInput = (AutoComplete) application.createComponent(AutoComplete.COMPONENT_TYPE);
        intDiligenciaIdEditInput.setId("intDiligenciaIdEditInput");
        intDiligenciaIdEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.intDiligenciaId}", Diligencia.class));
        intDiligenciaIdEditInput.setCompleteMethod(expressionFactory.createMethodExpression(elContext, "#{detalleDiligenciaBean.completeIntDiligenciaId}", List.class, new Class[] { String.class }));
        intDiligenciaIdEditInput.setDropdown(true);
        intDiligenciaIdEditInput.setValueExpression("var", expressionFactory.createValueExpression(elContext, "intDiligenciaId", String.class));
        intDiligenciaIdEditInput.setValueExpression("itemLabel", expressionFactory.createValueExpression(elContext, "#{intDiligenciaId.datFechaInicio} #{intDiligenciaId.datFechaFin} #{intDiligenciaId.strObservacion} #{intDiligenciaId.chrEstado}", String.class));
        intDiligenciaIdEditInput.setValueExpression("itemValue", expressionFactory.createValueExpression(elContext, "#{intDiligenciaId}", Diligencia.class));
        intDiligenciaIdEditInput.setConverter(new DiligenciaConverter());
        intDiligenciaIdEditInput.setRequired(false);
        htmlPanelGrid.getChildren().add(intDiligenciaIdEditInput);
        
        Message intDiligenciaIdEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        intDiligenciaIdEditInputMessage.setId("intDiligenciaIdEditInputMessage");
        intDiligenciaIdEditInputMessage.setFor("intDiligenciaIdEditInput");
        intDiligenciaIdEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(intDiligenciaIdEditInputMessage);
        
        HtmlOutputText strDescripcionEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strDescripcionEditOutput.setId("strDescripcionEditOutput");
        strDescripcionEditOutput.setValue("Str Descripcion: * ");
        htmlPanelGrid.getChildren().add(strDescripcionEditOutput);
        
        InputTextarea strDescripcionEditInput = (InputTextarea) application.createComponent(InputTextarea.COMPONENT_TYPE);
        strDescripcionEditInput.setId("strDescripcionEditInput");
        strDescripcionEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.strDescripcion}", String.class));
        LengthValidator strDescripcionEditInputValidator = new LengthValidator();
        strDescripcionEditInputValidator.setMaximum(200);
        strDescripcionEditInput.addValidator(strDescripcionEditInputValidator);
        strDescripcionEditInput.setRequired(true);
        htmlPanelGrid.getChildren().add(strDescripcionEditInput);
        
        Message strDescripcionEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        strDescripcionEditInputMessage.setId("strDescripcionEditInputMessage");
        strDescripcionEditInputMessage.setFor("strDescripcionEditInput");
        strDescripcionEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(strDescripcionEditInputMessage);
        
        HtmlOutputText strResponsableEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strResponsableEditOutput.setId("strResponsableEditOutput");
        strResponsableEditOutput.setValue("Str Responsable: * ");
        htmlPanelGrid.getChildren().add(strResponsableEditOutput);
        
        InputTextarea strResponsableEditInput = (InputTextarea) application.createComponent(InputTextarea.COMPONENT_TYPE);
        strResponsableEditInput.setId("strResponsableEditInput");
        strResponsableEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.strResponsable}", String.class));
        LengthValidator strResponsableEditInputValidator = new LengthValidator();
        strResponsableEditInputValidator.setMaximum(200);
        strResponsableEditInput.addValidator(strResponsableEditInputValidator);
        strResponsableEditInput.setRequired(true);
        htmlPanelGrid.getChildren().add(strResponsableEditInput);
        
        Message strResponsableEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        strResponsableEditInputMessage.setId("strResponsableEditInputMessage");
        strResponsableEditInputMessage.setFor("strResponsableEditInput");
        strResponsableEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(strResponsableEditInputMessage);
        
        HtmlOutputText datFechaRegistroEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        datFechaRegistroEditOutput.setId("datFechaRegistroEditOutput");
        datFechaRegistroEditOutput.setValue("Dat Fecha Registro: * ");
        htmlPanelGrid.getChildren().add(datFechaRegistroEditOutput);
        
        Calendar datFechaRegistroEditInput = (Calendar) application.createComponent(Calendar.COMPONENT_TYPE);
        datFechaRegistroEditInput.setId("datFechaRegistroEditInput");
        datFechaRegistroEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.datFechaRegistro}", Date.class));
        datFechaRegistroEditInput.setNavigator(true);
        datFechaRegistroEditInput.setEffect("slideDown");
        datFechaRegistroEditInput.setPattern("dd/MM/yyyy");
        datFechaRegistroEditInput.setRequired(true);
        htmlPanelGrid.getChildren().add(datFechaRegistroEditInput);
        
        Message datFechaRegistroEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        datFechaRegistroEditInputMessage.setId("datFechaRegistroEditInputMessage");
        datFechaRegistroEditInputMessage.setFor("datFechaRegistroEditInput");
        datFechaRegistroEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(datFechaRegistroEditInputMessage);
        
        HtmlOutputText txtImagenEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        txtImagenEditOutput.setId("txtImagenEditOutput");
        txtImagenEditOutput.setValue("Txt Imagen: * ");
        htmlPanelGrid.getChildren().add(txtImagenEditOutput);
        
        InputText txtImagenEditInput = (InputText) application.createComponent(InputText.COMPONENT_TYPE);
        txtImagenEditInput.setId("txtImagenEditInput");
        txtImagenEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.txtImagen}", String.class));
        htmlPanelGrid.getChildren().add(txtImagenEditInput);
        
        Message txtImagenEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        txtImagenEditInputMessage.setId("txtImagenEditInputMessage");
        txtImagenEditInputMessage.setFor("txtImagenEditInput");
        txtImagenEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(txtImagenEditInputMessage);
        
        HtmlOutputText chrEstadoEditOutput = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        chrEstadoEditOutput.setId("chrEstadoEditOutput");
        chrEstadoEditOutput.setValue("Chr Estado: * ");
        htmlPanelGrid.getChildren().add(chrEstadoEditOutput);
        
        InputText chrEstadoEditInput = (InputText) application.createComponent(InputText.COMPONENT_TYPE);
        chrEstadoEditInput.setId("chrEstadoEditInput");
        chrEstadoEditInput.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.chrEstado}", Character.class));
        chrEstadoEditInput.setRequired(true);
        htmlPanelGrid.getChildren().add(chrEstadoEditInput);
        
        Message chrEstadoEditInputMessage = (Message) application.createComponent(Message.COMPONENT_TYPE);
        chrEstadoEditInputMessage.setId("chrEstadoEditInputMessage");
        chrEstadoEditInputMessage.setFor("chrEstadoEditInput");
        chrEstadoEditInputMessage.setDisplay("icon");
        htmlPanelGrid.getChildren().add(chrEstadoEditInputMessage);
        
        return htmlPanelGrid;
    }

	public HtmlPanelGrid populateViewPanel() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application application = facesContext.getApplication();
        ExpressionFactory expressionFactory = application.getExpressionFactory();
        ELContext elContext = facesContext.getELContext();
        
        HtmlPanelGrid htmlPanelGrid = (HtmlPanelGrid) application.createComponent(HtmlPanelGrid.COMPONENT_TYPE);
        
        HtmlOutputText intDiligenciaIdLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        intDiligenciaIdLabel.setId("intDiligenciaIdLabel");
        intDiligenciaIdLabel.setValue("Int Diligencia Id:   ");
        htmlPanelGrid.getChildren().add(intDiligenciaIdLabel);
        
        HtmlOutputText intDiligenciaIdValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        intDiligenciaIdValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.intDiligenciaId}", Diligencia.class));
        intDiligenciaIdValue.setConverter(new DiligenciaConverter());
        htmlPanelGrid.getChildren().add(intDiligenciaIdValue);
        
        HtmlOutputText strDescripcionLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strDescripcionLabel.setId("strDescripcionLabel");
        strDescripcionLabel.setValue("Str Descripcion:   ");
        htmlPanelGrid.getChildren().add(strDescripcionLabel);
        
        InputTextarea strDescripcionValue = (InputTextarea) application.createComponent(InputTextarea.COMPONENT_TYPE);
        strDescripcionValue.setId("strDescripcionValue");
        strDescripcionValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.strDescripcion}", String.class));
        strDescripcionValue.setReadonly(true);
        strDescripcionValue.setDisabled(true);
        htmlPanelGrid.getChildren().add(strDescripcionValue);
        
        HtmlOutputText strResponsableLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        strResponsableLabel.setId("strResponsableLabel");
        strResponsableLabel.setValue("Str Responsable:   ");
        htmlPanelGrid.getChildren().add(strResponsableLabel);
        
        InputTextarea strResponsableValue = (InputTextarea) application.createComponent(InputTextarea.COMPONENT_TYPE);
        strResponsableValue.setId("strResponsableValue");
        strResponsableValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.strResponsable}", String.class));
        strResponsableValue.setReadonly(true);
        strResponsableValue.setDisabled(true);
        htmlPanelGrid.getChildren().add(strResponsableValue);
        
        HtmlOutputText datFechaRegistroLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        datFechaRegistroLabel.setId("datFechaRegistroLabel");
        datFechaRegistroLabel.setValue("Dat Fecha Registro:   ");
        htmlPanelGrid.getChildren().add(datFechaRegistroLabel);
        
        HtmlOutputText datFechaRegistroValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        datFechaRegistroValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.datFechaRegistro}", Date.class));
        DateTimeConverter datFechaRegistroValueConverter = (DateTimeConverter) application.createConverter(DateTimeConverter.CONVERTER_ID);
        datFechaRegistroValueConverter.setPattern("dd/MM/yyyy");
        datFechaRegistroValue.setConverter(datFechaRegistroValueConverter);
        htmlPanelGrid.getChildren().add(datFechaRegistroValue);
        
        HtmlOutputText txtImagenLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        txtImagenLabel.setId("txtImagenLabel");
        txtImagenLabel.setValue("Txt Imagen:   ");
        htmlPanelGrid.getChildren().add(txtImagenLabel);
        
        HtmlOutputText txtImagenValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        txtImagenValue.setId("txtImagenValue");
        txtImagenValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.txtImagen}", String.class));
        htmlPanelGrid.getChildren().add(txtImagenValue);
        
        HtmlOutputText chrEstadoLabel = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        chrEstadoLabel.setId("chrEstadoLabel");
        chrEstadoLabel.setValue("Chr Estado:   ");
        htmlPanelGrid.getChildren().add(chrEstadoLabel);
        
        HtmlOutputText chrEstadoValue = (HtmlOutputText) application.createComponent(HtmlOutputText.COMPONENT_TYPE);
        chrEstadoValue.setValueExpression("value", expressionFactory.createValueExpression(elContext, "#{detalleDiligenciaBean.detalleDiligencia.chrEstado}", String.class));
        htmlPanelGrid.getChildren().add(chrEstadoValue);
        
        return htmlPanelGrid;
    }

	public DetalleDiligencia getDetalleDiligencia() {
        if (detalleDiligencia == null) {
            detalleDiligencia = new DetalleDiligencia();
        }
        return detalleDiligencia;
    }

	public void setDetalleDiligencia(DetalleDiligencia detalleDiligencia) {
        this.detalleDiligencia = detalleDiligencia;
    }

	public List<Diligencia> completeIntDiligenciaId(String query) {
        List<Diligencia> suggestions = new ArrayList<Diligencia>();
        for (Diligencia diligencia : diligenciaService.findAllDiligencias()) {
            String diligenciaStr = String.valueOf(diligencia.getDatFechaInicio() +  " "  + diligencia.getDatFechaFin() +  " "  + diligencia.getStrObservacion() +  " "  + diligencia.getChrEstado());
            if (diligenciaStr.toLowerCase().startsWith(query.toLowerCase())) {
                suggestions.add(diligencia);
            }
        }
        return suggestions;
    }

	public String onEdit() {
        return null;
    }

	public boolean isCreateDialogVisible() {
        return createDialogVisible;
    }

	public void setCreateDialogVisible(boolean createDialogVisible) {
        this.createDialogVisible = createDialogVisible;
    }

	public String displayList() {
        createDialogVisible = false;
        findAllDetalleDiligencias();
        return "detalleDiligencia";
    }

	public String displayCreateDialog() {
        detalleDiligencia = new DetalleDiligencia();
        createDialogVisible = true;
        return "detalleDiligencia";
    }

	public String persist() {
        String message = "";
        if (detalleDiligencia.getIntDetalleDiligenciaId() != null) {
            detalleDiligenciaService.updateDetalleDiligencia(detalleDiligencia);
            message = "Successfully updated";
        } else {
            detalleDiligenciaService.saveDetalleDiligencia(detalleDiligencia);
            message = "Successfully created";
        }
        RequestContext context = RequestContext.getCurrentInstance();
        context.execute("createDialog.hide()");
        context.execute("editDialog.hide()");
        
        FacesMessage facesMessage = new FacesMessage(message);
        FacesContext.getCurrentInstance().addMessage(null, facesMessage);
        reset();
        return findAllDetalleDiligencias();
    }

	public String delete() {
        detalleDiligenciaService.deleteDetalleDiligencia(detalleDiligencia);
        FacesMessage facesMessage = new FacesMessage("Successfully deleted");
        FacesContext.getCurrentInstance().addMessage(null, facesMessage);
        reset();
        return findAllDetalleDiligencias();
    }

	public void reset() {
        detalleDiligencia = null;
        createDialogVisible = false;
    }

	public void handleDialogClose(CloseEvent event) {
        reset();
    }

	private static final long serialVersionUID = 1L;
}
